package com.neusoft.neuiotms.dcam.workflow.converter;

import org.springframework.beans.factory.annotation.Autowired;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcam.workflow.dto.WorkOrderDepositDTO;
import com.neusoft.neuiotms.dcam.workflow.model.WorkOrderDeposit;
import com.neusoft.neuiotms.dcam.workflow.repository.WorkOrderDepositRepository;

public class WorkOrderDepositConverter extends AbstractConverter<WorkOrderDeposit, WorkOrderDepositDTO> {

    @Autowired
    private WorkOrderDepositRepository workOrderDepositRepository;

    @Override
    public WorkOrderDeposit toModel(final WorkOrderDepositDTO dto) {
        final WorkOrderDeposit model;
        if (dto.isNew()) {
            model = new WorkOrderDeposit();
        } else {
            model = this.workOrderDepositRepository.getOne(dto.getId());
        }
        model.setWorkOrderNum(dto.getWorkOrderNum());
        model.setQuantity(dto.getQuantity());
        return model;
    }

    @Override
    public WorkOrderDepositDTO toDTO(final WorkOrderDeposit model, final boolean forListView) {
        final WorkOrderDepositDTO dto = new WorkOrderDepositDTO();
        dto.setId(model.getId());
        dto.setWorkOrderNum(model.getWorkOrderNum());
        dto.setQuantity(model.getQuantity());
        return dto;
    }

}
